﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using JYH.Framework;
using System.Windows.Forms;

namespace JYH.Framework
{
    public  class LicenseHelp
    {
        public static string ComputerInfofile = "A20181208.jyh";
        public static string RegistInfofile = "R20181208.jyh";
       public static void WriteRegistFile(string info,ref string fileName)
         {
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = RegistInfofile;
            }
            WriteFile(info, fileName);

        }
        public static void WriteComputerInfoFile(string info, ref string fileName)
{
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = ComputerInfofile;
            }
            WriteFile(info, fileName);
        }
        public static string ReadRegistFile(string fileName)
{
            return ReadFile(fileName);
        }
        public static string ReadComputerInfoFile(string fileName)
{
            return ReadFile(fileName);
        }

        public static bool ExistComputerInfofile(string fileName)
{
            return File.Exists(fileName);

        }
        public static bool ExistRegistInfofile(string fileName)

{
            return File.Exists(fileName);
        }
        private static void WriteFile(string info, string fileName)

{

            try

    {

                using (StreamWriter sw = new StreamWriter(fileName, false))

{

                    sw.Write(info);

                    sw.Close();
                }
            }

            catch 

    {

            }
        }
        private static string ReadFile(string fileName)

{
            string info = string.Empty;
            try

    {
                using (StreamReader sr = new StreamReader(fileName))
{
                    info = sr.ReadToEnd();
                    sr.Close();
                }

            }
            catch 

    {

            }
            return info;
        }

        public static string  GetLicenseCode(string RequestCode, string DateCode, string UserCode)
        {
            string Code = string.Empty;
            string key = string.Empty;
            key = Hardware.GetHardWareKey(RequestCode);
            Code = DateCode +"|"+ RequestCode + "|" + UserCode;
            Code = Security.DESEncrypt(Code, key);
            return Code;
            
        }
       



    }
}
